define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'millionproject/index' + location.search,
                    add_url: 'millionproject/add',
                    edit_url: 'millionproject/edit',
                    del_url: 'millionproject/del',
                    multi_url: 'millionproject/multi',
                    table: 'millionproject',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                undefinedText:'',
                showToggle: false,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: '', title: __('序号'), table: table,formatter: Table.api.formatter.natureorder, operate: false},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'status',title:'状态',operate:false,
                            formatter: function (value,row,index) {
                                if(value == 0) {
                                    return '<a href="javascript:;" class="btn btn-success btn-xs ">已审核</a>';
                                }else if(value == 100)
                                {
                                    return '<a href="centralcontact/checkedit/ids/' + row.id + '" class="btn btn-danger   btn-addtabs btn-xs" title="审核">待审核</a>';
                                }else if(value == 200){
                                    return '<a href="javascript:;" data-info="'+row.reject_reason+'" class="btn btn-warning btn-xs btn-rejectinfo">已驳回</a>';
                                }

                            }
                        },
                        // {field: 'sort', title: __('Sort')},
                        {field: 'name', title: __('Name')},
                        {field: 'investment_type_name', title: __('Investment_type_id'),operate: false},
                        {field: 'register_time', title: __('Register_time'),visible:false, operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'register_time_desc', title: __('Register_time_desc'),operate:false},
                        {field: 'investment_total', title: __('Investment_total'), operate:'BETWEEN'},
                        {field: 'registered_capital', title: __('Registered_capital'), operate:'BETWEEN'},
                        {field: 'external_registered_capital', title: __('External_registered_capital'), operate:'BETWEEN'},
                        {field: 'actual_registered_capital', title: __('Actual_registered_capital'), operate:'BETWEEN'},
                        // {field: 'industry_type_id', title: __('Industry_type_id'),visible:false},
                        {field: 'industry_type_name', title: __('Industry_type_name'),operate:false},
                        {field: 'floor_area', title: __('Floor_area')},
                        {field: 'street_id', title: __('Street_id'),visible:false,searchList: $.getJSON("selectlist/street")},
                        {field: 'street.name', title: __('Street_name'),operate:false},
                        {field: 'is_buy_land', title: __('Is_buy_land'),formatter:Table.api.formatter.radio,
                            searchList: {1: __('是'), 0: __('否')}
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            $("#btn-import-custom").click(function () {
                if(Config.isbinddep || Config.isSuperAdmin)
                {
                    var url = 'millionproject/import';
                    Fast.api.open(url, __('Import'), {});
                } else {
                    Layer.alert(__('您还未绑定部门，请先绑定'));
                }

            });
        },
        import:function() {
            Controller.api.bindevent();

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        checkedit: function(){
            $("#btn-pass").click(function () {
                var ids = $(this).data("ids");
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "centralcontact/checkpass" ,
                    data: {ids:ids},
                    success: function (ret) {
                        Layer.alert(__('提交成功'), function(index){
                            location.reload();
                        });
                    },
                    error : function(error) {
                        console.log(error);
                    }
                });
            });

            $("#btn-reject").click(function () {
                var ids = $(this).data("ids");
                Fast.api.open('centralcontact/checkreject/ids/'+ids, '驳回', {area: ["650px", "300px"]});
            });
            Controller.api.bindevent();
        },
        checkreject: function (){
            $("#btn-reject").click(function () {
                var ids = $(this).data("ids");
                var reject_reason = $("#reject_reason").val();

                Layer.confirm(__('确定要驳回吗?'), {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "centralcontact/checkreject" ,
                        data: {ids:ids,reject_reason:reject_reason},
                        success: function (ret) {
                            Layer.alert(__('驳回成功'), function(index){
                                parent.location.reload();
                            });
                        },
                        error : function(error) {
                            console.log(error);
                        }
                    });
                    Layer.closeAll();
                });
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});